package com.framework.activemq.dto;

import com.framework.common.api.IErrorCode;
import com.framework.common.api.ResultCode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @author lihanbo
 * @version 1.0
 * @date 2022/3/1 17:34
 */
@ApiModel("消息队列实体")
@Data
public class ActiveMqResult {
    private int code;
    private String message;

    private String token;
    private Long userid;
    private String username;

    @ApiModelProperty("终端")
    private String device;

    @ApiModelProperty("消息类型")
    private String msgType;

    @ApiModelProperty("内容")
    private Object data;

    public ActiveMqResult() {

    }

    public ActiveMqResult(int code, String msgType, String message) {
        this.code = code;
        this.message = message;
        this.msgType = msgType;
    }

    public ActiveMqResult(int code, String msgType, String message, Object data) {
        this.code = code;
        this.message = message;
        this.msgType = msgType;
        this.data = data;
    }

    /**
     * 成功返回结果
     */
    public static ActiveMqResult success(String msgType) {
        return new ActiveMqResult(ResultCode.SUCCESS.getCode(), msgType, ResultCode.SUCCESS.getMessage());
    }

    /**
     * 成功返回结果
     */
    public static ActiveMqResult success(String msgType, Object data) {
        return new ActiveMqResult(ResultCode.SUCCESS.getCode(), msgType, ResultCode.SUCCESS.getMessage(), data);
    }

    /**
     * 失败返回结果
     *
     * @param errorCode 错误码
     */
    public static ActiveMqResult failed(IErrorCode errorCode, String msgType) {
        return new ActiveMqResult(errorCode.getCode(), msgType, errorCode.getMessage(), null);
    }

    /**
     * 失败返回结果
     *
     * @param errorCode 错误码
     * @param message   错误信息
     */
    public static ActiveMqResult failed(IErrorCode errorCode, String msgType, String message) {
        return new ActiveMqResult(errorCode.getCode(), msgType, message, null);
    }

    /**
     * 失败返回结果
     *
     * @param message 提示信息
     */
    public static ActiveMqResult failed(String msgType, String message) {
        return new ActiveMqResult(ResultCode.FAILED.getCode(), msgType, message, null);
    }

    /**
     * 失败返回结果
     */
    public static ActiveMqResult failed(String msgType) {
        return failed(ResultCode.FAILED, msgType);
    }
}
